﻿using System;

namespace Aeon.Framework
{

/// <summary>
/// Class for multitextured textures.
/// After binding a texture, texture will change, iterating
/// circularly over the textures supplied in the constructor.
/// 
/// </summary>
public sealed class AeonTextureMany : ITexture
    {
    // --- Attributes:

    private ITexture[] textures;        // Texture names list.

    private int head;                   // Circular variable current texture.
    private int tail;                   // End of colors list.
    
    // --- Properties:                  // Pass through properties to the currently bound texture.
    
    public TextureCore Core 
        {
        get { return(textures[head].Core); } 
        set { textures[head].Core = value; } 
        }

    public String Name
        {
        get { return(textures[head].Name); }
        set { textures[head].Name = value; foreach(ITexture tex in textures) tex.Observer.Invoke(tex); }
        }

    public TextureChanged Observer 
        {
        get { return(textures[head].Observer); }
        set { foreach(ITexture tex in textures) { tex.Observer = value; } } 
        }
    
    // --- Constructor:
    
    public AeonTextureMany(params String[] many)
        {
        int count = many.Length;

        textures = new ITexture[count];
        tail = count-1;
        head = 0;

        for (int cnt = 0; cnt < count; cnt++) 
            { 
            textures[cnt] = AeonTexture.None; 
            textures[cnt].Name = many[cnt];
            }
        }
    
    // --- Public Methods:

    public void Bind()
        {
        textures[head].Core.Bind();
        
        head++;
        
        if (head > tail) head = 0;
        }
    
    }
    
    
}
